import threading

lock_nums = 0
no_lock_nums = 0
nums = 1000000

lock = threading.Lock()


def threading_func1():
    global lock_nums
    lock.acquire()
    for num in range(nums):
        lock_nums += 1
    lock.release()


def threading_func2():
    global lock_nums
    lock.acquire()
    for num in range(nums):
        lock_nums -= 1
    lock.release()


def nothreading_func1():
    global no_lock_nums
    for num in range(nums):
        no_lock_nums += 1


def nothreading_func2():
    global no_lock_nums
    for num in range(nums):
        no_lock_nums -= 1


if __name__ == "__main__":
    t1 = threading.Thread(target=threading_func1)
    t2 = threading.Thread(target=threading_func2)
    t3 = threading.Thread(target=nothreading_func1)
    t4 = threading.Thread(target=nothreading_func2)

    t1.start()
    t2.start()
    t3.start()
    t4.start()

    t1.join()
    t2.join()
    t3.join()
    t4.join()
    print("加了锁的操作{0}\n没加锁的操作{1}\n".format(lock_nums, no_lock_nums))

